<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>分页界面</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
</head>
<body class="wrap-container clearfix">
<div class="column-content-detail padt10" id="tool">
    <div class="cy-table-item-title" style="border:none;">
        学校简介
    </div>
    <div class="schoolStyle-txt-content">
        <div class="schoolStyle-tit-line">
            学校名称<span class="editbtn">编辑</span>
        </div>
        <div class="schoolStyle-txt-line">
            <div class="schoolStyle-txt-show" style=" overflow-y:auto!important;"></div>
            <textarea id="name" name="name" rows="6" style="display:none"></textarea>
            <div class="layui-form-item clearfix" style=" text-align:center;display:none;">
                <button class="layui-btn layui-btn-normal submitBtn">提交</button>
                <button class="layui-btn layui-btn-primary cancelBtn">取消</button>
            </div>
        </div>
    </div>
    <div class="schoolStyle-txt-content">
        <div class="schoolStyle-tit-line">
            学校概况<span class="editbtn">编辑</span>
        </div>
        <div class="schoolStyle-txt-line">
            <div class="schoolStyle-txt-show" style=" overflow-y:auto!important;"></div>
            <textarea id="situation" name="situation" rows="6" style="display:none"></textarea>
            <div class="layui-form-item clearfix" style=" text-align:center;display:none;">
                <button class="layui-btn layui-btn-normal submitBtn">提交</button>
                <button class="layui-btn layui-btn-primary cancelBtn">取消</button>
            </div>
        </div>
    </div>
    <div class="schoolStyle-txt-content">
        <div class="schoolStyle-tit-line">
            现任领导<span class="editbtn">编辑</span>
        </div>
        <div class="schoolStyle-txt-line">
            <div class="schoolStyle-txt-show" style=" overflow-y:auto!important;"></div>
            <textarea id="leader" name="leader" rows="6" style="display:none"></textarea>
            <div class="layui-form-item clearfix" style=" text-align:center;display:none;">
                <button class="layui-btn layui-btn-normal submitBtn">提交</button>
                <button class="layui-btn layui-btn-primary cancelBtn">取消</button>
            </div>
        </div>
    </div>
    <div class="schoolStyle-txt-content">
        <div class="schoolStyle-tit-line">
            校史沿革<span class="editbtn">编辑</span>
        </div>
        <div class="schoolStyle-txt-line">
            <div class="schoolStyle-txt-show" style=" overflow-y:auto!important;"></div>
            <textarea id="history" name="history" rows="6" style="display:none"></textarea>
            <div class="layui-form-item clearfix" style=" text-align:center;display:none;">
                <button class="layui-btn layui-btn-normal submitBtn">提交</button>
                <button class="layui-btn layui-btn-primary cancelBtn">取消</button>
            </div>
        </div>
    </div>
    <div class="schoolStyle-txt-content">
        <div class="schoolStyle-tit-line">
            办学思想<span class="editbtn">编辑</span>
        </div>
        <div class="schoolStyle-txt-line">
            <div class="schoolStyle-txt-show" style=" overflow-y:auto!important;"></div>
            <textarea id="thought" name="thought" rows="6" style="display:none"></textarea>
            <div class="layui-form-item clearfix" style=" text-align:center;display:none;">
                <button class="layui-btn layui-btn-normal submitBtn">提交</button>
                <button class="layui-btn layui-btn-primary cancelBtn">取消</button>
            </div>
        </div>
    </div>
    <div class="schoolStyle-txt-content">
        <div class="schoolStyle-tit-line">
            校园图示<span class="editbtn">编辑</span>
        </div>
        <div class="schoolStyle-txt-line">
            <div class="layui-upload-list" id="picture">
                <ul>
                    <li style="border:1px solid #ddd;text-align:center;line-height:85px;display:none;" class="addPictureBtn pictureBtn">
                        <span class="iconfont FS16" style="color:#DDD; display: inline-block">&#xe634;</span>
                    </li>
                </ul>
                <div style="clear: both"></div>
            </div>
            <div class="layui-form-item clearfix" style="text-align:center;display:none;">
                <button class="layui-btn layui-btn-primary cancelBtn">取消</button>
            </div>
        </div>
    </div>
    <div class="schoolStyle-txt-content">
        <div class="schoolStyle-tit-line">
            校园风光<span class="editbtn">编辑</span>
        </div>
        <div class="schoolStyle-txt-line">
            <div class="schoolStyle-txt-show" style=" overflow-y:auto!important;"></div>
            <textarea id="scenery" name="scenery" rows="6" style="display:none"></textarea>
            <div class="layui-form-item clearfix" style=" text-align:center;display:none;">
                <button class="layui-btn layui-btn-normal submitBtn">提交</button>
                <button class="layui-btn layui-btn-primary cancelBtn">取消</button>
            </div>
        </div>
    </div>
    <div class="schoolStyle-txt-content">
        <div class="schoolStyle-tit-line">
            学校荣誉<span class="editbtn">编辑</span>
        </div>
        <div class="schoolStyle-txt-line">
            <div class="layui-upload-list" id="honour">
                <ul>
                    <li style="border:1px solid #ddd;text-align:center;line-height:85px;display:none;" class="addPictureBtn honourBtn">
                        <span class="iconfont FS16" style="color:#DDD; display: inline-block">&#xe634;</span>
                    </li>
                </ul>
                <div style="clear: both"></div>
            </div>
            <div class="layui-form-item clearfix" style="text-align:center;display:none;">
                <button class="layui-btn layui-btn-primary cancelBtn">取消</button>
            </div>
        </div>
    </div>
    <div class="schoolStyle-txt-content">
        <div class="schoolStyle-tit-line">
            联系我们<span class="editbtn">编辑</span>
        </div>
        <div class="schoolStyle-txt-line">
            <div class="schoolStyle-label">坐标：
                <span class="spanlabel"></span>
                <input value="" type="text" class="spaninput" style="display: none; width: 300px !important;">
                <button class="layui-btn layui-btn-normal layui-btn-mid zuobiaobtn" type="button"
                        onclick="window.open('http://api.map.baidu.com/lbsapi/getpoint/index.html')" style="display: none">获取坐标
                </button>
            </div>
            <div class="schoolStyle-txt-show" style=" overflow-y:auto!important;">${schoolVo.contact}</div>
            <textarea id="contact" name="contact" rows="6" placeholder="请输入联系方式（多个中文逗号隔开）" style="display:none">${schoolVo.contact}</textarea>
            <div class="layui-form-item clearfix" style=" text-align:center;display:none;">
                <button class="layui-btn layui-btn-normal submitBtn">提交</button>
                <button class="layui-btn layui-btn-primary cancelBtn">取消</button>
            </div>
        </div>
    </div>
</div>
<!--操作-->
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    var applyId='${applyId}';
    var schoolVo = {};
    var layer = null;
    var baseutil = null;
    layui.use(['jquery', 'layer', 'upload', 'baseutil'], function () {
        var $ = layui.jquery,
            upload = layui.upload;
        layer = layui.layer;
        baseutil = layui.baseutil;

        function uploadImage(id) {
            var objectId = '';
            if (isBlank(schoolVo[id])) {
                objectId = new Date().getTime() + baseutil.acceptRandom(8);
            }
            var elem = '.' + id + 'Btn';
            upload.render({
                elem: elem
                , url: '/sysFile/singleImage'
                , accept: 'file'
                , multiple: true
                , data: {catalog: 'work/site/mult', objectId: isNotBlank(schoolVo[id]) ? schoolVo[id] : objectId}
                , auto: true
                , allDone: function (obj) {
                }
                , done: function (res) {
                    if (res.code === 0) {
                        if (isBlank(schoolVo[id])) {
                            schoolVo[id] = res.data.objectId;
                            schoolVo[applyId] =applyId;
                            delete schoolVo.pictureList;
                            delete schoolVo.honourList;
                            baseutil.AjaxPostMark('/work/site/school/addOrUpdate', schoolVo, function (data) {
                                if (isBlank(schoolVo.id)) {
                                    schoolVo.id = data;
                                }
                            });
                        }
                        var str = '<li>';
                        str += '<div class="delepictbn">';
                        str += '<span class="iconfont delebtn" onclick="deleteImage(this)" id="' + res.data.id + '">&#xe6a3;</span>';
                        str += '<span class="iconfont showbtn" onclick="showImage(this)" id="' + res.data.path + '">&#xe66e;</span>';
                        str += '</div>';
                        str += '<img src="/sysFile/showFileByPath?path=' + res.data.path + '">';
                        str += '</li>';
                        $('#' + id).find("li.addPictureBtn").before(str);
                        initListener();
                    } else {
                        dialog.msg(res.msg);
                    }
                }
            });
        }

        baseutil.AjaxPostMark('/work/site/school/select', {"applyId":applyId}, function (data) {
            if (data != null) {
                schoolVo = data;
                var content = $('.schoolStyle-txt-content');
                for (var i = 0; i < content.length; i++) {
                    var e = $(content[i]);
                    if (e.find("textarea").length > 0) {
                        var id = e.find("textarea").attr("id");
                        if (isNotBlank(schoolVo[id])) {
                            e.find(".schoolStyle-txt-show")[0].innerHTML = schoolVo[id];
                            e.find("textarea")[0].innerHTML = schoolVo[id];
                        }
                        if (e.find("input").length > 0) {
                            if (isNotBlank(schoolVo['longitude']) && isNotBlank(schoolVo['latitude'])) {
                                $('.spanlabel')[0].innerHTML = schoolVo['longitude'] + "," + schoolVo['latitude'];
                                $('.spaninput').val(schoolVo['longitude'] + "," + schoolVo['latitude']);
                            } else {
                                $('.spanlabel')[0].innerHTML = '暂未设置';
                            }
                        }
                    } else {
                        var id = e.find(".layui-upload-list").attr("id");
                        var list = schoolVo[id + "List"];
                        if (list != null) {
                            var str = '';
                            for (var j = 0; j < list.length; j++) {
                                str += '<li>';
                                str += '<div class="delepictbn">';
                                str += '<span class="iconfont delebtn" onclick="deleteImage(this)" id="' + list[j].id + '">&#xe6a3;</span>';
                                str += '<span class="iconfont showbtn" onclick="showImage(this)" id="' + list[j].path + '">&#xe66e;</span>';
                                str += '</div>';
                                str += '<img src="/sysFile/showFileByPath?path=' + list[j].path + '">';
                                str += '</li>';
                            }
                            e.find("li.addPictureBtn").before(str);
                            initListener();
                        }
                        uploadImage(id);
                    }
                }
            } else {
                $('.spanlabel')[0].innerHTML = '暂未设置';
            }
        });

        $('.editbtn').bind('click', function () {
            $(this).parents(".schoolStyle-txt-content").find(".editbtn").attr("style", "border:1px solid gray; color:gray; cursor:default");
            $(this).parents(".schoolStyle-txt-content").find(".layui-form-item").show();
            if ($(this).parents(".schoolStyle-txt-content").find("textarea").length > 0) {
                $(this).parents(".schoolStyle-txt-content").find(".schoolStyle-txt-show").hide();
                $(this).parents(".schoolStyle-txt-content").find("textarea").show();
                if ($(this).parents(".schoolStyle-txt-content").find("input").length > 0) {
                    $(this).parents(".schoolStyle-txt-content").find("span.spanlabel").hide();
                    $(this).parents(".schoolStyle-txt-content").find("input.spaninput").show();
                    $(this).parents(".schoolStyle-txt-content").find("button.zuobiaobtn").show();
                }
            } else {
                $(this).parents(".schoolStyle-txt-content").find("li.addPictureBtn").show();
            }
        });

        $('.submitBtn').bind('click', function () {
            var obj = $(this);
            var input = obj.parents(".schoolStyle-txt-content").find("input");
            if (input.length > 0) {
                if (isNotBlank($('.spaninput').val()) && $('.spaninput').val().split(",").length === 2) {
                    schoolVo.longitude = $('.spaninput').val().split(",")[0];
                    schoolVo.latitude = $('.spaninput').val().split(",")[1];
                }
            }
            var textarea = obj.parents(".schoolStyle-txt-content").find("textarea");
            var id = textarea.attr("id");
            schoolVo[id] = textarea.val();
            schoolVo[applyId] =applyId;
            delete schoolVo.pictureList;
            delete schoolVo.honourList;
            baseutil.AjaxPostMark('/work/site/school/addOrUpdate', schoolVo, function (data) {
                if (isBlank(schoolVo.id)) {
                    schoolVo.id = data;
                }
                obj.parents(".schoolStyle-txt-content").find(".editbtn").attr("style", "border:1px solid #5d9cec; color:#5d9cec; cursor:pointer");
                obj.parents(".schoolStyle-txt-content").find(".schoolStyle-txt-show").show();
                obj.parents(".schoolStyle-txt-content").find("textarea").hide();
                obj.parents(".schoolStyle-txt-content").find(".layui-form-item").hide();
                obj.parents(".schoolStyle-txt-content").find("li.addPictureBtn").hide();
                obj.parents(".schoolStyle-txt-content").find("span.spanlabel").show();
                obj.parents(".schoolStyle-txt-content").find("input.spaninput").hide();
                obj.parents(".schoolStyle-txt-content").find("button.zuobiaobtn").hide();
                obj.parents(".schoolStyle-txt-content").find(".schoolStyle-txt-show")[0].innerHTML = textarea.val();
                if (input.length > 0) {
                    if (isNotBlank($('.spaninput').val()) && $('.spaninput').val().split(",").length === 2) {
                        $('.spanlabel')[0].innerHTML = $('.spaninput').val();
                    } else {
                        $('.spanlabel')[0].innerHTML = '暂未设置';
                    }
                }
            });
        });

        $('.cancelBtn').bind('click', function () {
            $(this).parents(".schoolStyle-txt-content").find(".editbtn").attr("style", "border:1px solid #5d9cec; color:#5d9cec; cursor:pointer");
            $(this).parents(".schoolStyle-txt-content").find(".schoolStyle-txt-show").show();
            $(this).parents(".schoolStyle-txt-content").find("textarea").hide();
            $(this).parents(".schoolStyle-txt-content").find(".layui-form-item").hide();
            $(this).parents(".schoolStyle-txt-content").find("li.addPictureBtn").hide();
            $(this).parents(".schoolStyle-txt-content").find("span.spanlabel").show();
            $(this).parents(".schoolStyle-txt-content").find("input.spaninput").hide();
            $(this).parents(".schoolStyle-txt-content").find("button.zuobiaobtn").hide();
        });

        function initListener() {
            $(".layui-upload-list ul li").mouseover(function () {
                $(this).children('.delepictbn').show();
            });

            $(".layui-upload-list ul li").mouseout(function () {
                $(this).children('.delepictbn').hide();
            });
        }
    });

    function deleteImage(obj) {
        baseutil.AjaxPostMark("/sysFile/deleteById", {id: $(obj).attr('id')}, function () {
            $(obj).parent().parent().remove();
        });
    }

    function showImage(obj) {
        layer.open({
            type: 1
            , title: false
            , closeBtn: 0
            , skin: 'layui-layer-nobg'
            , shadeClose: true
            , content: '<img src="/sysFile/showFileByPath?path=' + $(obj).attr('id') + '" style="max-height:600px;max-width:100%;">'
            , scrollbar: false
        })
    }
</script>
</body>
</html>